/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 */
#ifndef BLIST_H_INCLUDED
#define BLIST_H_INCLUDED




#include <cstdlib>
#include <fstream>
#include <string>
#include <algorithm>
#   define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include "dataline.h"
#include "stringtonumb.h"
#include "encoding.h"
#include "exceptobjects.h"

#define BOOST_FILESYSTEM_NO_DEPRECATED ;

namespace bfs = boost::filesystem; //create an alias

namespace STLData{

    class blist {
    public:
        dataLine headerValue;
        std::string dtstName;
        bfs::path   dtstLibr;
        bfs::path   dtstPath;

    private:
        bfs::fstream dtstFile;
        long headerSize;
        int lineSize;
        std::streamsize bufferSize;
        int numLines;
        std::stringstream readBuffer;
        std::stringstream updtBuffer;
        std::stringstream appnBuffer;
        std::streampos presBufferPos;
        std::string lineCoded;
        blist() {}

    public:
        blist(const blist &other);
        blist(std::string filename, std::string filepath);
        blist(dataLine & variables, std::string &dataSetName,
              std::string &library);
        ~blist();

        bool readLine();
        bool modifyLine();
        bool appendLine();
        bool insertLine();
        bool appen(const blist other);
        bool sort();
        bool search();
        bool begin();
        bool end();
        blist & operator++();
        blist & operator++(int);
        blist & operator+=( blist &rhs);
        blist & operator=( blist &rhs);
        const blist operator+( blist &other) const ;
        dataLineElement& operator[](const dataLine::keyType searchKey) {
            return headerValue[searchKey];
        }
        bool readIndex(int index);
        bool sort(std::vector<std::string> sortFields,
                   std::vector<std::string> sortOrder);

    private:
        std::string codeHeader();
        bool decodeLine(const std::string lineString);
        bool flushBuffer();
        bool fillBuffer(std::streampos pos);
        bool appndBuffer();
    };

}



#endif // BLIST_H_INCLUDED
